const { projectId } = props
const useProjectId = ref()
import { watchEffect } from 'vue'
watchEffect(() => {
if (props.projectId) {
setTimeout(() => {
useProjectId.value = props.projectId
getTemplateCode()
getPopleList()
getAllJfPeople()
getData()
getStatusList()
console.log('项目阶段')
}, 500)
}
})

const milepostState = reactive({
searchForm: {
storyStatus: undefined,
storyName: undefined
},
dataList: [],
treeData: [],
targetKeys: [],
selectKeys: [],
SopTaskList: [],
addOrEditVisible: false,
dataLoading: false,
nextLoading: false,
okLoading: false,
addOrEditTitle: '',
modalForm: {
storyName: undefined,
timeRangeList: [],
taskList: [],
templateTaskId: []
},
current: 1,
statusList:[]
})
const formRef = ref(null)
const rules = {
storyName: [
{
required: true,
message: '请输入用户故事名称',
trigger: 'blur'
}
],
allTime: [{ required: false, message: '请选择任务起止时间!', trigger: 'blur' }],
functionAbbreviation: [{ required: true, message: '请输入功能简称', trigger: 'blur' }]
}
const currentData = ref({})
// 新建弹窗
function handleAdd() {
milepostState.addOrEditVisible = true
milepostState.addOrEditTitle = '新建用户故事'
currentData.value = {}
}
// 获取列表
function getData() {
milepostState.dataLoading = true
post('/solution-ppm/api/v2/built-in-system-ppm/project/story/search', {
projectId: useProjectId.value,
...milepostState.searchForm
})
.then(data => {
if (data.code !== 200) {
message.error(data.message)
milepostState.dataList = []
return
}
milepostState.dataList = data.data
})
.finally(() => {
milepostState.dataLoading = false
})
}
// 重置
function resetData() {
milepostState.searchForm.storyStatus = milepostState.searchForm.storyName = undefined
getData()
}
//     新建下一步获取任务
function getTask() {
formRef.value.validate().then(() => {
milepostState.nextLoading = true
post('/solution-ppm/api/v2/built-in-system-ppm/v2/platform/generate_task', {
templateTaskId: milepostState.modalForm.templateTaskId,
storyId: milepostState.modalForm.storyId,
functionAbbreviation: milepostState.modalForm.functionAbbreviation,
projectId: useProjectId.value
})
.then(data => {
milepostState.current = 2
milepostState.modalForm.taskList = data.data.map(item => {
return {
...item,
allTime: [item.startTime, item.endTime]
}
})
})
.finally(() => {
milepostState.nextLoading = false
})
})
}
const taskPeopleList = ref([])
function getPopleList() {
post(`/solution-ppm/api/v2/built-in-system-ppm/task/getTopUser/${useProjectId.value}`).then(data => {
taskPeopleList.value = data.data.map(item => {
return {
label: item,
value: item
}
})
})
}
const peopleList = ref([])
function getAllJfPeople() {
get('/solution-ppm/api/v2/built-in-system-ppm/pmgf/get/allUser').then(({ data }) => {
peopleList.value = data.userDtoList.map(item => {
return {
label: item.name,
value: item.name
}
})
})
}
// 快捷添加执行人
function handlerAddPtMbPeople(name, index) {
if (milepostState.modalForm.taskList[index].taskParticipantList.indexOf(name) !== -1) {
milepostState.modalForm.taskList[index].taskParticipantList = milepostState.modalForm.taskList[
index
].taskParticipantList.filter(item => item !== name)
} else {
milepostState.modalForm.taskList[index].taskParticipantList.push(name)
}
}
function cancelStory() {
currentData.value = {}
milepostState.addOrEditVisible = false
milepostState.modalForm = {
storyName: undefined,
timeRangeList: [],
taskList: [],
templateTaskId: []
}
}
const colorMap = {
'进行中': '#3875FF',
'未启动': '#8C8C8C',
'已完成': '#52C41A'
}
function getStatusColor(status) {
return colorMap[status]
}
const projectTemplate = ref()
function getTemplateCode() {
get(`/solution-ppm/api/v2/built-in-system-ppm/project/${useProjectId.value}`).then(data => {
projectTemplate.value = data.projectTemplate
})
}

//     获取穿梭框
function getTreeData() {
get(
`/solution-ppm/api/v2/built-in-system-ppm/v2/platform/template_milepost_task?templateCode=${projectTemplate.value}&functionAbbreviation=${milepostState.modalForm.functionAbbreviation}&projectId=${useProjectId.value}`
).then(data => {
milepostState.treeData = data.data
// flatten(JSON.parse(JSON.stringify(milepostState.treeData)))
console.log(milepostState.treeData)
milepostState.modalForm.selectKeys = []
})
}
// 保存模板项目
function confirmMbTask() {
formRef.value.validate().then(() => {
milepostState.okLoading = true
milepostState.modalForm.taskList.forEach(item => {
item.startTime = item.allTime[0]
item.endTime = item.allTime[1]
})
const api = currentData.value.id ? put : post

api(`/solution-ppm/api/v2/built-in-system-ppm/project/story`, {
projectId: useProjectId.value,
timeRangeList: milepostState.modalForm.timeRangeList,
storyName: milepostState.modalForm.storyName,
ppmPlatformTaskFormList: milepostState.modalForm.taskList,
id:currentData.value.id
})
.then(data => {
if (data.code !== 200) {
message.error(data.message)
return
}
message.success(data.message)

cancleMbTask()

getData()
})
.finally(() => {
milepostState.okLoading = false
})
})
}
// 关闭模板任务新建
function cancleMbTask() {
milepostState.addOrEditVisible = false
milepostState.current = 1
milepostState.modalForm.functionAbbreviation = undefined
milepostState.modalForm.templateTaskId = undefined
milepostState.modalForm = {
templateTaskId: [],
projectId: useProjectId.value,
functionAbbreviation: undefined,
taskList: []
}
}
const PromiseProxy = Promise
function confirmDelete(id) {
del(`/solution-ppm/api/v2/built-in-system-ppm/project/story/${id}`).then(data => {
if (data.code !== 200) {
message.error(data.message)
return
}
message.success(data.message)
getData()
})
}
function useDebounce(fn: (...args: any[]) => void, delay = 500) {
let timer: ReturnType<typeof setTimeout> | null = null

return function (...args: any[]) {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
fn(...args)
}, delay)
}
}
// 包一层防抖函数
const debounceGetData = useDebounce(getData, 500)
//     编辑story
function handleEditStory(record) {
console.log(record)
const item = cloneDeep(record)
Object.assign(milepostState.modalForm, item)
milepostState.modalForm.timeRangeList = [item.startTime, item.endTime]
currentData.value = item
milepostState.addOrEditVisible = true
milepostState.addOrEditTitle = '编辑用户故事'
}
function getStatusList(){
get('/solution-ppm/api/v2/built-in-system-ppm/dictionary/search/PTYHGS.RWZT').then(data => {
if (data.code !== 200) {
message.error(data.message)
return
}
milepostState.statusList = data.data.map(item => {
return {
label: item.itemName,
value: item.itemCode
}
})
})
}
